// Device/pages/Info/components/existence-component/index.js
import { customNavigate } from '@/utils/route'
const typeState = {
    '1': '离开',
    '2': '进入',
}
const deviceStatus = {
    '0': '离线',
    '1': '在线'
}
const app = getApp();
Component({
    data: {
        deviceData: [],
        staticPrefix: app.globalData.STATIC_PREFIX,
        lastRecord: null
    },
    properties: {
        deviceInfo: {
            type: Object,
            value: {}
        }
    },
    observers: {
        deviceInfo(value) {
            const data = new Map([
                ['device_status', '联网状态'],
                ['signal_strength', '信号强度']
            ]);
            let obj = {
                device_status: deviceStatus[value['device_status']],
                signal_strength: value['signal_strength'] ||'--'
            }
            let result = [];
            for (let [key, value] of Object.entries(obj)) {
                result.push({
                    key: data.get(key),
                    value,
                    path: '/Device/pages/Analysis/index?type=' + key
                })
            }
            this.setData({
                deviceData: result,
                lastRecord: value['human_body_data']?.length ? {
                    ...value['human_body_data'][0],
                    type: typeState[value['human_body_data'][0]['type']]
                } : null
            })
        }
    },
    methods: {
        onNavigate() {
            const { device_type, product_type, device_imei } = this.data.deviceInfo;
            const params = {
                device_type,
                product_type,
                device_imei
            }
            customNavigate({
                url: `/Device/pages/History/index`,
                params
            })
        }
    }
})